#! /usr/bin/env python
# -*- coding: utf-8 -*-
import time

from naoqi import ALProxy
ip="192.168.1.12"
port=9559
redBallProxy=ALProxy("ALRedBallDecetion",ip,port)
camProxy=ALProxy("ALVideoDevice",ip,port)
memoryProxy=ALProxy("ALMemory",ip,port)
camProxy.setActiveCamera(1)
period=500
redBallProxy.subscribe("Test_RedBall",period,0.0)
memValue="redBallDetected"
time.sleep(0.5)
val=memoryProxy.getData(memValue)
if(val and isinstance(val,list) and len(val)>=2):
    timeStamp=val[0]
    ballInfo=val[1]
    try:
        print"centerX=",ballInfo[0],"centerY=",ballInfo[1]
        print"sizeX=",ballInfo[2],"sizeY=",ballInfo[3]
    except Exception,e:
        print"RedBall deleted,but it seems getData is invalid.ALValue="
        print val
        print"Error msg %s" %(str(e))
    else:
        print"Error with getData.ALValue=%s"%(str(val))
    redBallProxy.unsubscribe("Test_RedBall")